package com.cn.fileTest;

import org.junit.Test;

import java.io.File;

/**
 * 文件目录的属性
 */
public class FileTest1 {

    /**
     * 判断文件或目录是否存在
     */
    @Test
    public void test1(){
        File file = new File("src/main/resources/test.txt");
        System.out.println("File exists:"+file.exists());
    }

    /**
     * 判断是否是文件
     */
    @Test
    public void test2(){
        File file = new File("src/main/resources/test.txt");
        System.out.println("Is file: " + file.isFile());
    }

    /**
     * 判断是否是目录
     */
    @Test
    public void test3(){
        File dir = new File("src/main/resources");
        System.out.println("Is directory: " + dir.isDirectory());
    }

    /**
     * 获取文件或目录的名称。
     */
    @Test
    public void test4(){
        File file = new File("sra/main/resources/test.txt");
        System.out.println("File Name:"+file.getName());
        File dir = new File("src/main/resources");
        System.out.println("Dir Name: " + dir.getName());
    }

    /**
     * 获取文件的路径
     */
    @Test
    public void test5(){
        File file = new File("src/main/resources/test.txt");
        System.out.println("Path:"+file.getPath());
    }

    /**
     * 获取文件的绝对路径
     */
    @Test
    public void test6(){
        File file = new File("src/main/resources/test.txt");
        System.out.println("Path:"+file.getAbsolutePath());
    }








}
